<?php

namespace App\Http\Controllers;

use App\PointsModel;
use App\UserModel;
use Illuminate\Http\Request;

class MinAppController extends Controller
{
    public function addToTable(Request $request)
    {
        $name = $request->input("name");
        $pwd = $request->input("pwd");
        if($name!=null && $pwd!=null){
            UserModel::create([
                'name'=>$name,
                'pwd'=>$pwd
            ]);
            $data = [
                'msg'=>"操作成功",
                'err'=>0,
            ];
        }else{
            $data = [
                'msg'=>"操作失败，没有获取到name或者pwd参数",
                'err'=>1,
            ];
        }
        return $data;
    }

    public function addPoints(Request $request)
    {
        $data = $request->input();
        $point = PointsModel::create($data);
        if($point){
            $data = [
                'msg'=>"操作成功",
                'err'=>0,
            ];
        }else {
            $data = [
                'msg' => "操作失败",
                'err' => 1,
            ];
        }
        return $data;
    }

    public function getPoints(Request $request)
    {
        $data = PointsModel::get();
        return $data;
    }
}
